function [varargout]=Equ_HH(PP,SS,MODEL,JacobianFlag,Dev_Input,Dev_Output,TimePrintFlag)

%% Preliminaries
VAR         =   MODEL.VAR;
HH          =   MODEL.EquBlock.HH;

if nargin<=3
    JacobianFlag    =   0;
end
if nargin<=4
    Dev_Input       =   zeros(HH.Dim.In,1);
    Dev_Output      =   zeros(HH.Dim.Out,1);
elseif ( isempty(Dev_Input) || isempty(Dev_Output) )
    Dev_Input       =   zeros(HH.Dim.In,1);
    Dev_Output      =   zeros(HH.Dim.Out,1);
end
if nargin<=6
    TimePrintFlag   =   0;
end
if TimePrintFlag
    TimeStart       =   tic;
end
%% Evaluation
%--------------------------------------------------------------------------
% Pre-Transformation: Input Deviations to Input Levels
%--------------------------------------------------------------------------

for ii=1:HH.Num.In
    TempVar     =   HH.Var.In{ii};
    TempDev     =   Dev_Input(HH.LocIdx.In.(TempVar));
    TempLevel   =   VAR.(TempVar).Dev2Level(TempDev);
    eval(['Dev_',TempVar,'=TempDev;'])
    eval([TempVar,'=TempLevel;'])
end


%--------------------------------------------------------------------------
% 1. Decision Problem
%--------------------------------------------------------------------------
C   =   ( SS.BETA*(1+ir_ext)*(1+dEp)/(1+Pirp) )^(-1/PP.NU_C)*Cp;
L   =   ( C^(-PP.NU_C)*(1-TAU)*w/SS.PSI )^( 1/PP.NU_L );
B   =   (1+ir_ext)*( T+Profit+(1-TAU)*w*L-C+Lag_B*(1+dE)/(1+Pir) );
%--------------------------------------------------------------------------
% Post-Transformation: Output Levels to Ouput Deviations
%--------------------------------------------------------------------------
Dev_Left    =   zeros(HH.Dim.Out,1);
for ii=1:HH.Num.Out
    TempVar     =   HH.Var.Out{ii};
    eval(['TempLevel=',TempVar,';']);
    TempDev     =   VAR.(TempVar).Level2Dev(TempLevel);
    Dev_Left(HH.LocIdx.Out.(TempVar)) ...
                =   TempDev;
end
%% Return Objectives

switch JacobianFlag
    case 0
        varargout{1}    =   -Dev_Output+Dev_Left;
    case 1
        TempFun         =   @(Dev_Input)Equ_HH(PP,SS,MODEL,0,Dev_Input,Dev_Output);
        Jac             =   struct();
        Jac.Input       =   fdjac(TempFun,Dev_Input);
        Jac.Output      =   -speye(MODEL.EquBlock.HH.Dim.Out);
        
        for ii=1:HH.Num.In
            TempVar         =   HH.Var.In{ii};
            Jac.(TempVar)   =   Jac.Input(:,HH.LocIdx.In.(TempVar));
        end
        for ii=1:HH.Num.Out
            TempVar         =   HH.Var.Out{ii};
            Jac.(TempVar)   =   Jac.Output(:,HH.LocIdx.Out.(TempVar));
        end
        varargout{1}    =   Jac;
end
if TimePrintFlag
    TimeElapsed     =   toc(TimeStart);
    fprintf(['Jacobian of HH Block is done: ',...
             'Elapse Time=',num2str(TimeElapsed,'%.2f'),'s','\n']);
end

